package com.czzapp.xiaoyumemo.util;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.czzapp.xiaoyumemo.model.Memo;
import com.czzapp.xiaoyumemo.view.NoticeActivity;

//到时提醒模块
public class MemoNoticeUtil {
	public static final String MEMO_NAME = "MEMO";
	
	public static void addNotice(Context context, Memo memo) {
		int alarmType = AlarmManager.RTC_WAKEUP;
		PendingIntent pendingIntent = getNoticeIntent(context, memo);
		((AlarmManager)context.getSystemService(Context.ALARM_SERVICE)).set(alarmType, memo.getDelayDate().getTime(), pendingIntent);
	}
	
	public static void delNotice(Context context, Memo memo) {
		PendingIntent pendingIntent = getNoticeIntent(context, memo);
		((AlarmManager)context.getSystemService(Context.ALARM_SERVICE)).cancel(pendingIntent);
	}
	
	private static PendingIntent getNoticeIntent(Context context, Memo memo) {
		Intent intent = new Intent();
		intent.setClass(context, NoticeActivity.class);
		intent.putExtra(MEMO_NAME, memo.getId());
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		PendingIntent pendingIntent = PendingIntent.getActivity(context, memo.getId(), intent, Intent.FLAG_ACTIVITY_NEW_TASK);
		return pendingIntent;
	}
}
